import {Browser, Page, chromium} from '@playwright/test';
import {Before, After, AfterAll, BeforeAll} from '@cucumber/cucumber';
import { pageFixture } from './pageFixture';

let browser:Browser;
let page:Page;
let content:any;

BeforeAll(async function(){
    browser = await chromium.launch({headless: true});
});

Before(async function(){
    content = await browser.newContext();
    page = await browser.newPage();
    pageFixture.page = page;
});

After(async function ({pickle}) {
    //screenshot
    const img = await pageFixture.page.screenshot({path: `./test-results/screenshots/${pickle.name}.png`});
    await this.attach(img, 'image/png');
    await pageFixture.page.close();
    await content.close();
});

AfterAll(async function() {
    await browser.close();
});